import request from '@/utils/request'

const userApi = {
  Login: '/login',
  Logout: '/logout',
  // get my info
  UserInfo: '/getInfo',
  SendSms: '/system/sysSms/sendSms',
  sso_login: '/cetc-sso/api/v3/auth/doLogin',
  getCallbackUrl: '/oauth2.0/authorize'
}

/**
 * login func
 * @param parameter
 * @returns {*}
 */
export function login(parameter) {
  return request({
    url: userApi.Login,
    method: 'post',
    data: parameter
  })
}

/**
 * login func
 * @param parameter
 * @returns {*}
 */
export function loginBySms(parameter) {
  return request({
    url: '/system/sysSms/loginBySms',
    method: 'post',
    data: parameter
  })
}

export function getInfo() {
  return request({
    url: userApi.UserInfo,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

// export function logout() {
//   return request({
//     url: userApi.Logout,
//     method: 'delete',
//     headers: {
//       'Content-Type': 'application/json;charset=UTF-8'
//     }
//   })
// }

export function singleLogout() {
  return request({
    url: '/cetc-sso/cxf/api/v1/ssoSession/remove',
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function logout() {
  return request({
    url: '/cetc-sso/logout',
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

// 获取验证码
export function getCodeImg() {
  return request({
    url: '/captchaImage',
    method: 'get',
    timeout: 20000
  })
}

// 获取手机验证码
export function getSmsCaptcha(parameter) {
  return request({
    url: userApi.SendSms,
    method: 'post',
    data: parameter
  })
}

// 注册方法
export function register(data) {
  return request({
    url: '/register',
    headers: {
      isToken: false
    },
    method: 'post',
    data: data
  })
}

/*
 * @description: sso 登录
 * @params: params { Object } body入参
 * @author: liumingpeng
 * @date: 2023-4-23 17:13:44
 */
export function apiDoLogin(params) {
  return request({
    url: userApi.sso_login,
    method: 'post',
    data: params
  })
}

/*
 * @description: 登录成功后拼接URL交给后端
 * @params: params { Object } query入参
 * @author: liumingpeng
 * @date: 2023-4-23 17:13:51
 */
export function apiGetCallbackUrl(params) {
  return request({
    // http://192.168.20.15:9000/oauth2.0/authorize?client_id=client&response_type=code&redirect_uri=http://www.baidu.com&oauth_timestamp=1489739502583
    url: userApi.getCallbackUrl,
    method: 'get',
    params
  })
}

export function envConfig(params) {
  return request({
    // http://192.168.20.15:9000/oauth2.0/authorize?client_id=client&response_type=code&redirect_uri=http://www.baidu.com&oauth_timestamp=1489739502583
    url: '/env-config',
    method: 'get',
    params
  })
}
